<#import "../common/common.ftl" as common />
<@common.page>
	<!-- Classes -->
	<script type="text/javascript" src="${res}/js/ui/check.BaseDataQualityQuery.js"></script>
	<!-- ux	-->
	
	<script type="text/javascript">
		check.NewestMonthProblemQuery = Ext.extend(check.BaseDataQualityQuery, {
			gridViewConfig: {},
		    pageSize: EXT_PAGE_SIZE,
		    sm: new Ext.grid.RowSelectionModel({
				//dataIndex: this.ID
			}),
			
			initGridPanel: null,
			//penal1
		    store1: null,
		    storeMapping1: ["comcode","comcname","wrongcnt"],
		    grid1:null,
		    cm1: new Ext.grid.CellSelectionModel(),
		    
		    //penal2
		    store2: null,
		    storeMapping2: ["comcode","departcode","departname","wrongcnt"],
		    grid2:null,
		    cm2: new Ext.grid.CellSelectionModel(),
		    
		    //penal3
		    store3: null,
		    storeMapping3: ["comcode","checkpoint","checkpointname","wrongcnt"],
		    grid3:null,
		    cm3: new Ext.grid.CellSelectionModel(),
		    
			
			constructor: function(config) {
				config = config || {};
				
				this.pageSize = config.pageSize || EXT_PAGE_SIZE;
		        
		        var viewConfig = Ext.apply({
		            forceFit: true
		        }, this.gridViewConfig);
		        
		        if(this.view){
		            Ext.apply(this.gridPanel,{
		                view: this.view
		            });
		        };
		        
		        /**********************************grid1***************************/
		        this.cm1.defaultSortable = true;
		        
		        this.cm1 = new Ext.grid.ColumnModel([
		            new Ext.grid.RowNumberer(),
				    {
				        header:"公司代码",
				        dataIndex:"comcode",
				        align:'center',
				        style:'font-weight:bold;',
		                sortable:true
			        },{
				        header:"公司名称",
				        dataIndex:"comcname",
				        align:'center',
		                sortable:true,
		                style:'font-weight:bold;'
			        },{
				        header:"问题笔数",
				        width:80,
				        style:'font-weight:bold;',
				        align:'center',
				        dataIndex:"wrongcnt",
		                sortable:true
			        }
			    ]);
		        
		        this.store1 = new Ext.data.JsonStore({
	                id: this.ID,
	                url: AJAX_ROOT_URL+"/dataquality/queryNewestInCompany",
	                root: EXT_STORE_ROOT,
	                totalProperty: EXT_STORE_TOTALPROPERTY,
	                remoteSort: true,
	                fields: this.storeMapping1
	            });
		        
		        this.grid1 = new Ext.grid.GridPanel({
		            id:Ext.id(),
		            store:this.store1,
		            cm:this.cm1,
		            sm:this.sm,
		            //autoHeight:true,
		            //height:600,
		            trackMouseOver:false,
		            labelStyle:'font-weight:bold;',
		            anchor:'100%',
		            loadMask: true,
		            //超过长度带自动滚动条
				    autoScroll:true,
				    border:false,
				    //collapsible: true,
		            animCollapse:false,
		            viewConfig:{
		            	forceFit: true
		            },
		            listeners: {
		                'contextmenu':function(e) {
		                    e.stopEvent();
		                },
		                'cellcontextmenu':function(Grid,Rindex,Cindex,E){
					    }
		            },
		            bbar: new Ext.PagingToolbar({
		                pageSize: this.pageSize,
		                store: this.store1,
		                buttonAlign:'right'
		            })
		        });
		        
		        /**********************************grid2***************************/
		        this.cm2.defaultSortable = true;
		        
		        this.cm2 = new Ext.grid.ColumnModel([
		            new Ext.grid.RowNumberer(),
				    {
				        header:"公司代码",
				        dataIndex:"comcode",
				        align:'center',
				        style:'font-weight:bold;',
		                sortable:true
			        },{
				        header:"产品线代码",
				        dataIndex:"departcode",
				        align:'center',
		                sortable:true,
		                style:'font-weight:bold;'
			        },{
				        header:"产品线名称",
				        dataIndex:"departname",
				        align:'center',
		                sortable:true,
		                style:'font-weight:bold;'
			        },{
				        header:"问题笔数",
				        width:80,
				        style:'font-weight:bold;',
				        align:'center',
				        dataIndex:"wrongcnt",
		                sortable:true
			        }
			    ]);
		        
		        this.store2 = new Ext.data.JsonStore({
	                id: this.ID,
	                url: AJAX_ROOT_URL+"/dataquality/queryNewestInProduct",
	                root: EXT_STORE_ROOT,
	                totalProperty: EXT_STORE_TOTALPROPERTY,
	                remoteSort: true,
	                fields: this.storeMapping2
	            });
		        
		        this.grid2 = new Ext.grid.GridPanel({
		            id:Ext.id(),
		            store:this.store2,
		            cm:this.cm2,
		            sm:this.sm,
		            //autoHeight:true,
		            //height:600,
		            trackMouseOver:false,
		            labelStyle:'font-weight:bold;',
		            anchor:'100%',
		            loadMask: true,
				    autoScroll:true,
				    border:false,
				    //collapsible: true,
		            animCollapse:false,
		            viewConfig:{
		            	forceFit: true
		            },
		            listeners: {
		                'contextmenu':function(e) {
		                    e.stopEvent();
		                },
		                'cellcontextmenu':function(Grid,Rindex,Cindex,E){
					    }
		            },
		            bbar: new Ext.PagingToolbar({
		                pageSize: this.pageSize,
		                store: this.store2,
		                buttonAlign:'right'
		            })
		        });
		        
		        /**********************************grid3***************************/
		        this.cm3.defaultSortable = true;
		        
		        this.cm3 = new Ext.grid.ColumnModel([
		            new Ext.grid.RowNumberer(),
				    {
				        header:"公司代码",
				        dataIndex:"comcode",
				        align:'center',
				        style:'font-weight:bold;',
		                sortable:true
			        },{
				        header:"检查点代码",
				        dataIndex:"checkpoint",
				        align:'center',
		                sortable:true,
		                style:'font-weight:bold;'
			        },{
				        header:"检查点名称",
				        dataIndex:"checkpointname",
				        align:'center',
		                sortable:true,
		                style:'font-weight:bold;'
			        },{
				        header:"问题笔数",
				        width:80,
				        style:'font-weight:bold;',
				        align:'center',
				        dataIndex:"wrongcnt",
		                sortable:true
			        },{
				        header:"导出",
				        width:50,
				        style:'font-weight:bold;',
				        align:'center',
				        renderer: function(value, metaData, record, rowIndex, colIndex, store) {
				        	var aLink = '<img src="${res}/images/excel.png" style="cursor:pointer" onclick="onExport(\''+record.json.comcode+'\',\''+record.json.checkpoint+'\')" title="导出excel"/>';
					      	return aLink;
					   	}
			        }
			    ]);
		        
		        this.store3 = new Ext.data.JsonStore({
	                id: this.ID,
	                url: AJAX_ROOT_URL+"/dataquality/queryNewestInCheckPoint",
	                root: EXT_STORE_ROOT,
	                totalProperty: EXT_STORE_TOTALPROPERTY,
	                remoteSort: true,
	                fields: this.storeMapping3
	            });
		        
		        this.grid3 = new Ext.grid.GridPanel({
		            id:Ext.id(),
		            store:this.store3,
		            cm:this.cm3,
		            sm:this.sm,
		            //autoHeight:true,
		            //maxHeight:300,
		            //height: 500,
		            trackMouseOver:false,
		            labelStyle:'font-weight:bold;',
		            anchor:'100%',
		            loadMask: true,
		            //超过长度带自动滚动条
				    autoScroll:true,
				    border:false,
				    //collapsible: true,
		            animCollapse:false,
		            viewConfig:{
		            	forceFit: true
		            },
		            listeners: {
		                'contextmenu':function(e) {
		                    e.stopEvent();
		                },
		                'cellcontextmenu':function(Grid,Rindex,Cindex,E){
					    }
		            },
		            bbar: new Ext.PagingToolbar({
		                pageSize: this.pageSize,
		                store: this.store3,
		                buttonAlign:'right'
		            })
		        });
		        
		    	this.initGridPanel = new Ext.TabPanel({
			    	activeTab: 0,
			    	autoHeight:true,
			    	autoScroll:true,
			    	items:[{
			    		title:'公司维度', 
			    		autoHeight:true,    
		               	autoWidth:true,    
		               	autoScroll:true,    
		              	frame:true, 
			    		items:this.grid1,
			    		listeners:{
	    					'afterlayout': function() {
								this.grid1.setHeight(document.body.clientHeight - 265);
	    					},
	    					scope:this
			    		}
		    		},{
		    			title:'产品线维度', 
		    			autoHeight:true,    
		               	autoWidth:true,    
		               	autoScroll:true,    
		              	frame:true, 
			    		items:this.grid2,
			    		listeners:{
	    					'afterlayout': function() {
		    					////自己维护高度自适应
								this.grid2.setHeight(document.body.clientHeight - 265);
	    					},
	    					scope:this
			    		}
	    			},{
		    			title:'检查点维度', 
		    			autoHeight:true,    
		               	autoWidth:true,    
		               	autoScroll:true,    
		              	frame:true, 
			    		items:this.grid3,
			    		listeners:{
	    					'afterlayout': function() {
	    						//this.grid3.setHeight(this.grid3.ownerCt.ownerCt.ownerCt.getHeight())
	    						//alert(this.grid3.ownerCt.ownerCt.ownerCt.getHeight());
	    						//console.info(Ext.getBody());
	    						/***
								alert('网页可见区域高：'+document.body.clientHeight  ); 
								alert('网页可见区域高：'+document.body.offsetHeight  );     
								alert('网页正文全文高：'+document.body.scrollHeight  ); 
								alert('网页被卷去的高：'+document.body.scrollTop     );
								alert('屏幕分辨率的高：'+window.screen.height        );
								alert('屏幕可用工作区高度：'+window.screen.availHeight   );
								***/
								//alert(document.body.scrollHeight);
								////自己维护高度自适应
								this.grid3.setHeight(document.body.clientHeight - 265);
	    					},
	    					scope:this
			    		}
	    			}]
			    });
		    	
		    	var configs = Ext.apply({
		    		
		        },config);
		    	
		    	check.NewestMonthProblemQuery.superclass.constructor.call(this,configs);
			},
		    onSearch: function(){
		    	var pageParam = {
		    		'start': 0,
	                'limit': this.pageSize
		    	};
		    	this.store1.setBaseParam('checkDate', Ext.getCmp('checkDate').getValue());
		    	this.store1.setBaseParam('product', Ext.getCmp('product').getValue());
		    	this.store1.setBaseParam('comcode', Ext.getCmp('comcode').data.comcode);
		    	this.store1.setBaseParam('gradeLevel', Ext.getCmp('comcode').data.gradelevel);
		    	this.store1.setBaseParam('checkPoint', Ext.getCmp('checkPoint').getValue());
		    	
				this.store2.setBaseParam('checkDate', Ext.getCmp('checkDate').getValue());
		    	this.store2.setBaseParam('product', Ext.getCmp('product').getValue());
		    	this.store2.setBaseParam('comcode', Ext.getCmp('comcode').data.comcode);
		    	this.store2.setBaseParam('gradeLevel', Ext.getCmp('comcode').data.gradelevel);
		    	this.store2.setBaseParam('checkPoint', Ext.getCmp('checkPoint').getValue());
		    	
		    	this.store3.setBaseParam('checkDate', Ext.getCmp('checkDate').getValue());
		    	this.store3.setBaseParam('product', Ext.getCmp('product').getValue());
		    	this.store3.setBaseParam('comcode', Ext.getCmp('comcode').data.comcode);
		    	this.store3.setBaseParam('gradeLevel', Ext.getCmp('comcode').data.gradelevel);
		    	this.store3.setBaseParam('checkPoint', Ext.getCmp('checkPoint').getValue());
		    	
				this.store1.load({
		            params: pageParam
		        });
				this.store2.load({
		            params: pageParam
		        });
				this.store3.load({
		            params: pageParam
		        });
			}
		});
		
		function onExport(comcode,checkPoint) {
			var checkDate = Ext.getCmp('checkDate').getValue();
	    	//var product = Ext.getCmp('product').getValue();
	    	//var comcode = record.comcode;
	    	//var gradeLevel = Ext.getCmp('comcode').data.gradelevel;
	    	//var checkPoint = record.checkpoint;
	    	/***
			Ext.Ajax.request({
				url: AJAX_ROOT_URL+'/dataquality/doExcelSelf',
				params: { 
					'checkDate': checkDate,
					'product': product,
					'comcode': comcode,
					'gradeLevel': gradeLevel,
					'checkPoint': checkPoint
				}
			});
	    	***/
			window.open(AJAX_ROOT_URL+'/dataquality/doExcelSelf?checkDate='+checkDate+'&comcode='+Ext.util.Format.trim(comcode)+'&checkPoint='+checkPoint,'导出EXCEL报表','');
		}
		
		Ext.onReady(function(){
			var reportQuery = new check.NewestMonthProblemQuery({
				needCheckPoint:true,
				userCompany: {${userCompany}},
				renderTo:Ext.getBody()
			});
		});
	</script>
	</head>
<body style="background-color:transparent">
</body>
</@common.page>